package cn.lifei.basic.service.impl;

import cn.lifei.basic.mapper.BaseMapper;
import cn.lifei.basic.query.BaseQuery;
import cn.lifei.basic.service.IBaseService;
import cn.lifei.basic.util.PageInfo;
import cn.lifei.org.domain.Department;
import cn.lifei.org.mapper.DepartmentMapper;
import cn.lifei.org.query.DepartmentQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Transactional
    @Override
    public void delete(Serializable id) {
        baseMapper.delete(id);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }


    @Override
    public T queryById(Serializable id) {
        return baseMapper.queryById(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }



    @Override
    public PageInfo<T> queryPage(BaseQuery baseQuery) {
        // 查询总条数
        long total = baseMapper.queryTotal(baseQuery);
        if (total == 0) {
            return new PageInfo<>();
        }
        // 查询数据
        List<T> list = baseMapper.queryList(baseQuery);
        return new PageInfo<>(total,list);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        baseMapper.batchDelete(ids);
    }

}
